<!DOCTYPE html>
<html class="x-admin-sm">

<head>
	<meta charset="UTF-8">
	<title>电子学会比赛管理系统</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
	<link rel="stylesheet" href="./css/font.css">
	<link rel="stylesheet" href="./css/common.css">
	<link rel="stylesheet" href="./css/xadmin.css">
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script type="text/javascript" src="./js/xadmin.js"></script>
</head>

<body>
<div class="x-nav">
	<span class="layui-breadcrumb">
			<a href="">首页</a>
			<a><cite>系统管理</cite></a>
			<a><cite>账号管理</cite></a>
	</span>
	<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
		<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
	</a>
</div>
<div class="layui-fluid" id="content" v-cloak>
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<div class="layui-card">
				<div class="layui-card-body ">
					<form class="layui-form layui-col-space5 flex" style="display: flex;" @submit.prevent>
						<div class="layui-input-inline layui-show-xs-block flex">
							<div class="mr5" style="width: 40px;">账号</div>
							<input type="text" name="number" placeholder="账号" autocomplete="off" class="layui-input"></div>
						<div class="layui-input-inline layui-show-xs-block">
							<button class="layui-btn" lay-submit="" lay-filter="search">
								<i class="layui-icon">&#xe615;</i></button>
						</div>
					</form>
				</div>
				<div>
					<div class="layui-card-header">
						<!--<button class="layui-btn layui-btn-danger" onclick="delAll()">-->
						<!--<i class="layui-icon"></i>批量删除-->
						<!--</button>-->
						<button class="layui-btn" onclick="xadmin.open('添加用户','add-account.html',1000,600)">
							<i class="layui-icon"></i>添加
						</button>
					
					</div>
					<div class="layui-card-body">
						<table class="layui-table layui-form" id="table">
							<span>共计{{total}}条数据</span>
						</table>
						<section id="page"></section>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
</body>
<script src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/abkj/slAjax.js"></script>
<script src="./js/vue.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/admininfo.js"></script>
<script type="text/javascript" src="./js/abkj/ext/login.js"></script>

<script type="text/javascript" src="./js/abkj/auth/api/userrole.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/role.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/account.js"></script>
<script type="text/javascript" src="./js/abkj/auth/api/userinfo.js"></script>
<script type="text/javascript" src="./js/abkj/fun_tool.js"></script>
<script>
	var app=new Vue({
		el: '#content',
		data: {
			adminList:[],
			accountList:[],
			roleList:[],
			list:[],
			total: 0,
			pageNo: 1,
			pageSize: 1000,
			status:['审核','待审核' ,'通过', '不通过'],
			participate:['审核','参赛' ,'弃权' ],
			cols: [ //表头
				{field: 'index', title: '序号', width: 80},
				{field: 'account', title: '账号'},
				{field: 'roleName', title: '权限'},
				{field: 'operating', title: '操作', width: 135, templet: '#operating'},
			]
		},
		mounted: function () {
			this.getData()
			var vm = this
			layui.use('form', function () {
				layui.form.on('submit(search)', function (data) {
					if(data.field.number == ''){
							layer.msg("请输入查询帐号", function () {
								return;
							})
						}else{
							console.log(data)
							vm.searchAccount(data.field.number)
					}

					// layer.msg(JSON.stringify(data.field), function () {
					// location.href = 'index.html'
					// })
				})
			})
		},
		methods:{
			opentab:function(name,url){
				//单击事件
				xadmin.add_tab(name,url)
			},
			loadAdminList:function(varQueryData){
				var vm = this
				// var queryData = {
				// 	    page:{
				// 	        current:1, //当前页数
				// 	        size:10   //每页长度
				// 	    },
				// 	    cond:{ //条件
				// 	        eq:{ // 多条件对象
		  //                   }
				// 	    }
				// };
				AdminInfoPageList(varQueryData,function(data){
					vm.adminList=data;
					vm.total = data.total
					var ids=[];
					for(var i=0; i<vm.adminList.records.length; ++i){
						ids.push(vm.adminList.records[i].id);
					}
					var accountParam={
						in:{
							data:ids,
							attrName:"id"
						}
					}
					AccountqueryList(accountParam,function(data){
						vm.accountList=data;

						vm.list = []

						for(var i=0;i<data.length;++i){
							var listItem={
								index:i+(vm.adminList.current-1)*vm.adminList.size,
								id:data[i].id,
								idStr:"id_"+data[i].id,
								account:data[i].userName,
								status:data[i].isProhibit
							}
							var roles=vm.getRoleInfoFromMem(data[i].id);
							var rolesDesc="无"
							for(var t=0;t<roles.length;++t){
								if(t == 0){
									rolesDesc=roles[t].roleName;
								}else{
									rolesDesc+=(","+roles[t].roleName);
								}
							}
							listItem.roleName=rolesDesc;
							vm.list.push(listItem);

						}

					},function(status,message){

					})
				},function(status,message){

				})
			},
			loadNextPage:function(varPageNumber,varPageSize){// 加载下一页数据
				var queryData = {
				    page:{
				        current:varPageNumber, //当前页数
				        size:varPageSize   //每页长度
				    },
				    cond:{ //条件
				        eq:{ // 多条件对象
	                    }
				    }
				};
				vm.loadAdminList(queryData);
			},
			getRoleInfoFromMem:function(varUserId){
				var rolesOfUser=[];
				for(var i=0;i<this.roleList.length;++i){
					if(this.roleList[i].userId == varUserId){
						rolesOfUser.push(this.roleList[i])
					}
				}
				return rolesOfUser;
			},
			loadRoleList:function(){
				var vm = this
				UserRolequeryList({},function(data){
					vm.roleList=data;
					var queryData = {
					    page:{
					        current: vm.pageNo, //当前页数
					        size: vm.pageSize   //每页长度
					    },
					    cond:{ //条件
					        eq:{ // 多条件对象
		                    }
					    }
					};
					vm.loadAdminList(queryData);
				},function(status,message){

				})
			},
			searchAccount:function(varUserName){//账户检索
				var vm = this
				var accountParam={
					eq:{
						userName:varUserName
					}
				}
				AccountqueryList(accountParam,function(data){
					accountList=data;
					vm.init()
					if(accountList.length > 0){
						;
						var queryData = {
						    page:{
						        current: vm.pageNo, //当前页数
						        size: vm.pageSize   //每页长度
						    },
						    cond:{ //条件
						        eq:{ // 多条件对象
						        	id:accountList[0].id
			                    }
						    }
						};
						vm.loadAdminList(queryData);
					}
				},function(status,message){

				})
			},
			getData: function () {
				this.loadRoleList();
				this.init()
			},
			stop: function (data) {
				data = JSON.parse(data)
				var text = data.state === 1 ? '启用' : '禁用'
				var reqObj={
					id:data.id,
					isProhibit:data.status === 1?0:1
				}
				// 禁用启用逻辑
				layer.confirm('确定' + text + '吗？', function () {
					// 掉接口
					AccountupdateById(reqObj,function(data){
						layer.msg(text + '成功!', {icon: 1})
						location.reload()
					})

				})
			},
			init:function() {
				var that = this
				var vm = this
				layui.use(['table'], function () {
					// var laypage = layui.laypage;
					// //执行一个laypage实例
					// laypage.render({
					// 	elem: 'test1' //注意，这里的 test1 是 ID，不用加 # 号
					// 	,count: 16 //数据总数，从服务端得到
					// });
                    console.log(JSON.stringify(that.list))
                    that.list=that.list.reverse()
					var table = layui.table
					//头工具栏事件
					table.render({
						elem: '#table',
						url:'',
						title: '用户数据表',
						cols: [that.cols],
						data: that.list,
						page:false,
						limit:10000,
						// count: vm.adminList.total
					})
					app.total=app.list.length
					// layui.laypage.render({
					// 	elem: 'page',
					// 	count: vm.total,
					// 	current: vm.pageNo,
					// 	limit: 1000,
					// 	jump: function (obj, first) {
					// 		if (first) return
					// 		vm.pageNo = obj.curr
					// 		vm.getData()
					// 	}
					// })
				})
			}
		}
	})
	function deletemydata(id){
     if (confirm("是否删除该用户吗？")){
			 delAccount(id,function(data){
				 alert("删除成功！")
				 location.reload()
			 })

		 }
	}
	function  closewindow(){

	}
</script>
<script type="text/html" id="operating">
	<a href="javascript:;" class="layui-table-link" onclick=app.stop('{{JSON.stringify(d)}}')>{{ d.status === 1 ? '启动' : '禁用' }}</a>
	<a href="javascript:;"  onclick="xadmin.open('添加用户','add-account.html?id={{d.id}}',1000,600)" class="layui-table-link">编辑</a>
	<a href="javascript:;"  onclick="deletemydata('{{d.id}}')" class="layui-table-link">删除</a>

</script>


</html>
